package com.park.controller;

import com.park.bean.Employee;
import com.park.bean.Tickets;
import com.park.bean.TicketsCap;
import com.park.common.CommonResult;
import com.park.dao.ITicketsDao;
import com.park.service.ITicketsService;
import com.park.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

@RestController
@CrossOrigin
public class TicketsController {
    @Autowired
    ITicketsService ticketsService;

    @GetMapping("tickets")
    public CommonResult getTickets(Tickets tickets, Page page){
        List<Tickets> res=ticketsService.getTickets(tickets,page);
        int count=ticketsService.getCount(tickets);
        HashMap map=new HashMap();
        map.put("res",res);
        map.put("count",count);
        return CommonResult.success(map);
    }

    @GetMapping("tickets/detail")
    public CommonResult getDetail(Tickets tickets){
        List<String> list=ticketsService.getDetail(tickets);
        return CommonResult.success(list);
    }

    //添加数据
    @PostMapping("tickets")
    public CommonResult postTickets(@RequestBody Tickets tickets){
        int count=ticketsService.postTickets(tickets);
        if(count>0){
            return CommonResult.success(tickets);
        }else{
            return CommonResult.fail();
        }
    }

    @DeleteMapping("tickets/{id}")
    public CommonResult delTickets(@PathVariable int id){
        int count= ticketsService.delTickets(id);
        if(count>0){
            return CommonResult.success();
        }else{
            return CommonResult.fail();
        }
    }

    @PutMapping("tickets")
    public CommonResult editTickets(@RequestBody Tickets tickets){
        int count=ticketsService.editTickets(tickets);
        if(count>0){
            return CommonResult.success(tickets);
        }else{
            return CommonResult.fail();
        }
    }



}
